<?php

require_once("class2.php");

$text .= e107shop_search();

function e107shop_search() {

    global $search_info, $key, $pref, $query;

    $sql = new db();
    $gen2 = new convert();
    $nothingfound = true;
    
    $sql_c = new db(); // second database connection

    $linkprefix = "<img src=\"".THEME."images/bullet2.gif\" alt=\"bullet\" />";
    $linkprefix .= "<b><a href=\"".e_PLUGIN."e107shop/product_details.php?";

    if ($sql->db_Select('e107shop_products', "*", "product_name REGEXP('".$query."') or description REGEXP('".$query."') ORDER BY ID DESC")) {

        $nothingfound = false;
        while($row = $sql -> db_Fetch()){
            extract($row);
            
            $cat=""; // returned category id for each product found in search
            //get category_id for found product ID
        $shopqry = "SELECT category_id
           FROM `#e107shop_category_matrix`
           WHERE product_id=".$row[ID]."
           GROUP BY category_id";
      $sql_c->db_Query_all($shopqry);
      while($row2 = $sql_c -> db_Fetch()){
      $cat=$row2[0];
    }
            
            
            $que = parsesearch($product_name, $ID, $query);
            $ans = parsesearch($description, $query);
            $text .= $linkprefix."product=$ID&cat=$cat\">$que</a></b><br /><span class=\"smalltext\"></span><br />$ans<br /><br />";

        }
    }

    if ($nothingfound) {
        $text .= LAN_198;
    }
return $text;

}
